-- CMP DELETE ALL TABLES (CAMBIAR UN PAR DE VISTAS)

(
select
  'ALTER TABLE ' + tc.table_name + ' DROP CONSTRAINT ' + tc.constraint_name + ';'
from
  INFORMATION_SCHEMA.TABLES t
  ,INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
where
  t.table_name = tc.table_name
  and tc.constraint_name not like '%_pk'
  and tc.constraint_name not like 'pk_%'
  and t.table_catalog='<schema>'
) UNION (
select
  'DROP TABLE ' + t.table_name + ';'
from
  INFORMATION_SCHEMA.TABLES t
where
  t.table_catalog='<schema>'
)



ALTER TABLE Account DROP CONSTRAINT FK_Account_CreatedById_User_UserId;
ALTER TABLE Account DROP CONSTRAINT FK_Account_DepartmentId_Department_DepartmentId;
ALTER TABLE Account DROP CONSTRAINT FK_Account_ModifiedById_User_UserId;
ALTER TABLE Account DROP CONSTRAINT FK_Account_OriginatingLeadId_Lead_LeadId;
ALTER TABLE Account DROP CONSTRAINT FK_Account_OwnerId_User_UserId;
ALTER TABLE Account DROP CONSTRAINT FK_Account_PrimaryContactId_Contact_ContactId;
ALTER TABLE Contact DROP CONSTRAINT FK_Contact_CreatedById_User_UserId;
ALTER TABLE Contact DROP CONSTRAINT FK_Contact_ModifiedById_User_UserId;
ALTER TABLE Contact DROP CONSTRAINT FK_Contact_OriginatingLeadId_Lead_LeadId;
ALTER TABLE Contact DROP CONSTRAINT FK_Contact_OwnerId_User_UserId;
ALTER TABLE Contract DROP CONSTRAINT FK_Contract_BillingCustomerId_Account_AccountId;
ALTER TABLE Contract DROP CONSTRAINT FK_Contract_CreatedById_User_UserId;
ALTER TABLE Contract DROP CONSTRAINT FK_Contract_DepartmentId_Department_DepartmentId;
ALTER TABLE Contract DROP CONSTRAINT FK_Contract_ModifiedById_User_UserId;
ALTER TABLE Contract DROP CONSTRAINT FK_Contract_OpportunityId_Opportunity_OpportunityId;
ALTER TABLE Contract DROP CONSTRAINT FK_Contract_OwnerId_User_UserId;
ALTER TABLE Contract DROP CONSTRAINT FK_Contract_TransactionCurrencyId_TransactionCurrency_TransactionCurrencyId;
ALTER TABLE Lead DROP CONSTRAINT FK_Lead_CreatedById_User_UserId;
ALTER TABLE Lead DROP CONSTRAINT FK_Lead_DepartmentId_Department_DepartmentId;
ALTER TABLE Lead DROP CONSTRAINT FK_Lead_ModifiedById_User_UserId;
ALTER TABLE Lead DROP CONSTRAINT FK_Lead_OwnerId_User_UserId;
ALTER TABLE Metadata_Attribute DROP CONSTRAINT FK_Metadata_Attribute_AttributeTypeId_Metadata_AttributeType_AttributeTypeId;
ALTER TABLE Metadata_Attribute DROP CONSTRAINT FK_Metadata_Attribute_EntityId_Metadata_Entity_EntityId;
ALTER TABLE Metadata_Attribute DROP CONSTRAINT FK_Metadata_Attribute_OptionSetId_Metadata_OptionSet_OptionSetId;
ALTER TABLE Opportunity DROP CONSTRAINT FK_Opportunity_CreatedById_User_UserId;
ALTER TABLE Opportunity DROP CONSTRAINT FK_Opportunity_DepartmentId_Department_DepartmentId;
ALTER TABLE Opportunity DROP CONSTRAINT FK_Opportunity_ModifiedById_User_UserId;
ALTER TABLE Opportunity DROP CONSTRAINT FK_Opportunity_OriginatingLeadId_Lead_LeadId;
ALTER TABLE Opportunity DROP CONSTRAINT FK_Opportunity_OwnerId_User_UserId;
ALTER TABLE Opportunity DROP CONSTRAINT FK_Opportunity_TechnicianId_User_UserId;
ALTER TABLE Opportunity DROP CONSTRAINT FK_Opportunity_TransactionCurrencyId_TransactionCurrency_TransactionCurrencyId;
ALTER TABLE Project DROP CONSTRAINT FK_Project_ContractId_Contract_ContractId;
ALTER TABLE Project DROP CONSTRAINT FK_Project_CreatedById_User_UserId;
ALTER TABLE Project DROP CONSTRAINT FK_Project_ManagerId_User_UserId;
ALTER TABLE Project DROP CONSTRAINT FK_Project_ModifiedById_User_UserId;
ALTER TABLE Project DROP CONSTRAINT FK_Project_SaleServiceId_User_UserId;
ALTER TABLE ProjectVersion DROP CONSTRAINT FK_ProjectVersion_CreatedById_User_UserId;
ALTER TABLE ProjectVersion DROP CONSTRAINT FK_ProjectVersion_ModifiedById_User_UserId;
ALTER TABLE ProjectVersion DROP CONSTRAINT FK_ProjectVersion_ProjectId_Project_ProjectId;
ALTER TABLE [User] DROP CONSTRAINT FK_User_CreatedById_User_UserId;
ALTER TABLE [User] DROP CONSTRAINT FK_User_DepartmentId_Department_DepartmentId;
ALTER TABLE [User] DROP CONSTRAINT FK_User_ModifiedById_User_UserId;
ALTER TABLE [User] DROP CONSTRAINT FK_User_ParentUserId_User_UserId;
DROP TABLE Account;
DROP TABLE Contact;
DROP TABLE Contract;
DROP TABLE Criteria;
DROP TABLE Department;
DROP TABLE ImportMap;
DROP TABLE Lead;
DROP TABLE Metadata_Attribute;
DROP TABLE Metadata_AttributeType;
DROP TABLE Metadata_Entity;
DROP TABLE Metadata_OptionSet;
DROP TABLE Opportunity;
DROP TABLE Project;
DROP TABLE ProjectVersion;
DROP VIEW SummaryIterationTask;
DROP VIEW SummaryProjectTask;
DROP TABLE TransactionCurrency;
DROP TABLE [User];
